package com.service.sales;

import com.mapper.sales.ProductMapper;
import com.pojo.sales.view.SalesProductR;
import com.pojo.sales.view.SalesTop5ProductView;
import com.service.iter.sales.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 产品服务业务层
 *
 * @author admin
 * 2023/06/19
 */
@Service
@Transactional
public class ProductServiceImpl implements IProductService {
    /**
     * 产品映射器
     */
    @Autowired
    ProductMapper productMapper;

    /**
     * 销售产品
     *
     * @return {@link List}<{@link SalesProductR}>
     */
    @Override
    public List<SalesProductR> getSaleProducts() {
        List<SalesProductR> saleProducts = productMapper.getSaleProducts();
        for (int i = 0; i < saleProducts.size(); i++) {
            saleProducts.get(i).setProductRanking(i + 1L);
        }
        return saleProducts;
    }

    /**
     * 前五名销售产品
     *
     * @return {@link List}<{@link SalesTop5ProductView}>
     */
    @Override
    public List<SalesTop5ProductView> getTopFiveSaleProduct() {
        return productMapper.getTopFiveSaleProduct();
    }
}
